import QtQuick 2.2

Image {
    id: ru
    source: "LIFT/ui3/bk.png"
    width: 768
    height: 1024
    signal start;
    property bool lightflag : true
    property bool fanflag : true
    signal keypress(int key)

    property bool lighten : false
    property bool fanen : false
    //property bool bellen : false


    Item{
        x:208
        y:182
        width: 194
        height: 454
        opacity: 1
        Column {
            id: column0
            anchors { fill: parent;topMargin: 0; leftMargin: 0}
            spacing: 64

         Image {
                id: light
                source: "LIFT/ui3/light_dn.png"
                MouseArea {
                    id: mouseArea
                    anchors.fill: parent

                    onClicked:{
                        lighten = true
                        if(lightflag)
                        {
                            light.source="LIFT/ui3/light.png"
                            keypress(14)
                        }
                        else
                        {
                            light.source= "LIFT/ui3/light_dn.png"
                            keypress(13)
                        }
                        //lightflag = !lightflag

                        timerdl.start()
                    }
                }
            }

            Image {
                id: fan
                source: "LIFT/ui3/fan_dn.png"
                MouseArea {
                    id: mouseArea1
                    anchors.fill: parent

                    onClicked:{
                        fanen = true
                        if(fanflag)
                        {
                            fan.source="LIFT/ui3/fan.png"
                            keypress(12)
                        }
                        else
                        {
                            fan.source= "LIFT/ui3/fan_dn.png"
                            keypress(11)
                        }
                        //fanflag = !fanflag
                        timerdl1.start()
                    }

                }
            }
        }
    }

    Item{
        x:466
        y:182
        width: 94
        height: 454
        opacity: 1
        Column {
            id: column1
            anchors { fill: parent;topMargin: 0; leftMargin: 0}
            spacing: 26

            Button{width: 94;height: 94;source0: "LIFT/ui3/close.png";source1: "LIFT/ui3/close_dn.png";onBtclicked:{keypress(10);btreply(str)}}
            Button{width: 94;height: 94;source0: "LIFT/ui3/open.png";source1: "LIFT/ui3/open_dn.png";onBtclicked:{keypress(9);btreply(str)}}
            //Button{width: 94;height: 94;source0: "LIFT/ui3/bell.png";source1: "LIFT/ui3/bell_dn.png";onBtclicked:{btreply(str)}}
            Image {
                id: bell
                source: "LIFT/ui3/bell.png"
                MouseArea {
                    id: mouseArea2
                    anchors.fill: parent

                    onClicked:{
                        root.bellen = true
                        if(root.jflag)
                        {
                            bell.source="LIFT/ui3/bell.png"
                            keypress(16)
                        }
                        else
                        {
                            bell.source= "LIFT/ui3/bell_dn.png"
                            keypress(15);
                        }
                        //root.jflag = !root.jflag
                        timerdl2.start()
                    }
                }
            }
            Button{width: 94;height: 94;source0: "LIFT/ui3/cancel.png";source1:"LIFT/ui3/cancel_dn.png";onBtclicked:{ru.start()}}
        }
    }

    Timer {
         id: timerlf;
         interval: 500;
         running: true;
         repeat: false;
         triggeredOnStart: false;
         onTriggered:{

//             if(root.jflag)
//                 keypress(15);//开警铃
//             else
//                 keypress(16);//关警铃

//             if(lightflag)
                  keypress(13);//开灯
//             else
//                 keypress(14);//关灯

//             if(fanflag)
                  keypress(11);//开风扇
//             else
//                 keypress(12);//关风扇

              //console.log("change fan and light")
         }
     }

    Timer {
         id: timerdl;
         interval: 500;
         running: false;
         repeat: false;
         triggeredOnStart: false;
         onTriggered:{
                lighten = false
             }
         }

    Timer {
         id: timerdl1;
         interval: 500;
         running: false;
         repeat: false;
         triggeredOnStart: false;
         onTriggered:{
                 fanen = false
             }
         }

    Timer {
         id: timerdl2;
         interval: 500;
         running: false;
         repeat: false;
         triggeredOnStart: false;
         onTriggered:{
                root.bellen = false
             }
         }

    function btreply(str) {

    }

    function bellkey(str){
        if( str===16 )
            bell.source="LIFT/ui3/bell.png"
        else if( str===15 )
            bell.source= "LIFT/ui3/bell_dn.png"
    }

    function light_c(num)
    {
        if(lighten)
            return
//        if(num===lightflag)
//            return
        lightflag = num
        if(!lightflag)
        {
            light.source="LIFT/ui3/light.png"
            //keypress(14)
        }
        else
        {
            light.source= "LIFT/ui3/light_dn.png"
            //keypress(13)
        }

    }

    function fan_c(num)
    {
        if(fanen)
            return
//        if(num===fanflag)
//            return
        fanflag = num
        if(!fanflag)
        {
            fan.source="LIFT/ui3/fan.png"
            //keypress(12)
        }
        else
        {
            fan.source= "LIFT/ui3/fan_dn.png"
            //keypress(11)
        }

    }

    function jl_c(num)
    {
        if(root.bellen)
            return
//        if(num===root.jflag)
//            return
        root.jflag = num
        if(!root.jflag)
        {
            bell.source="LIFT/ui3/bell.png"
            keypress(16)
        }
        else
        {
            bell.source= "LIFT/ui3/bell_dn.png"
            keypress(15);
        }

    }
}
